package com.zzyl.nursing;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import cn.hutool.json.JSONUtil;
import com.zzyl.common.utils.http.HttpUtils;
import org.junit.Test;

import java.util.HashMap;

public class Httptest {

    @Test
    public void testPage(){
//        //构建查询参数
        HashMap<String, Object> dataMap = new HashMap<>();
        dataMap.put("pageNum",1);
        dataMap.put("pageSize",3);
//        令牌
        String token = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImxvZ2luX3VzZXJfa2V5IjoiMTA2MmUxOWMtMmZhYi00MzA3LWE0OWQtNTcxYjc4MjFjYmIzIn0.XvpViaW3a87Y9hsB7AFGhHK3pU-SXyGFBB3ZhUai7Yexn1YTEa_783WlS3M1Q7JllOqpqixbxWJ1trTsDc4HOQ";
        String url = "http://localhost:9000/nursing/nursingProject/list";

        HttpResponse response = HttpUtil.createRequest(Method.GET,url)
                        .header("authorization",token)
                                .form(dataMap)
                                        //执行
                                        .execute();
//       //响应状态码
        int status = response.getStatus();
        //响应结果
        String result = response.body();
        System.out.println(status);
        System.out.println(result);
    }


    @Test
    public void testPost(){
        HashMap<String, Object> paramMap = new HashMap<>();

        paramMap.put("name", "护理项目测试");
        paramMap.put("orderNo", 1);
        paramMap.put("unit", "次");
        paramMap.put("price", 10.00);
        paramMap.put("image", "https://viy-slwl-oss.oss-cn-hangzhou.aliyunncs.com/ae7cf766-fb7b-49ff-a73c-c86c25f280e1.png");
        paramMap.put("nursingRequirement", "无特殊要求");
        paramMap.put("status", 1);
        String url = "http://localhost:9000/nursing/nursingProject";
        String token = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImxvZ2luX3VzZXJfa2V5IjoiMTA2MmUxOWMtMmZhYi00MzA3LWE0OWQtNTcxYjc4MjFjYmIzIn0.XvpViaW3a87Y9hsB7AFGhHK3pU-SXyGFBB3ZhUai7Yexn1YTEa_783WlS3M1Q7JllOqpqixbxWJ1trTsDc4HOQ";

//        String result = HttpUtil.post(url, JSONUtil.toJsonStr(paramMap));
        HttpResponse response=HttpUtil.createPost(url)
                        .header("authorization",token)
                                .body(JSONUtil.toJsonStr(paramMap),"application/json;charset=utf-8")
                                        .execute();

        System.out.println(response.getStatus());
        System.out.println(response.body());

    }








}
